package view.screen;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextField;

import view.base.FormScreen;
import base.ScreenActionListener;
import controller.Controller;

public final class ConfigurationMenuScreen extends FormScreen{

	private final TextField userName;

	public ConfigurationMenuScreen(ScreenActionListener controller, String currentUsername){
		super(controller, "Menu");
		
		userName = new TextField("New username:", null, 50, TextField.EMAILADDR);
		
		this.append(new TextField("Current Username", currentUsername, currentUsername.length(), TextField.UNEDITABLE));
		this.append(userName);

		this.addCommand(new Command("Next", Command.OK, 1));//falta meter NEXT no switch de baixo
		this.addCommand(new Command("Confirm username", Command.OK, 1));
		this.addCommand(new Command("Picture update", Command.OK, 1));

		this.setCommandListener(this);

	}

	public void commandAction(Command c, Displayable d) {
		switch (c.getCommandType()) {
		case Command.OK:
			if(c.getLabel().equals("Confirm username")) {
				String name = userName.getString();
				controller.viewAction(Controller.CONFIRM_COMMAND, name.equals("")?null:name); // TODO review name change
			} else if(c.getLabel().equals("Picture update"))
				controller.viewAction(Controller.IMAGE_COMMAND, null);
			else
				controller.viewAction(Controller.NEXT_COMMAND, null);
			break;
		default:
			super.commandAction(c, d);
			break;
		}
	}
}

